import requests
from redis import StrictRedis
import requests.exceptions as e
import os


def test():
    try:
        dizhi=input('请输入你要保存的文件位置(如F:/......):')
        cu=dizhi.replace("\\",'/')
        o=1

        redis = StrictRedis(host='172.18.200.5', port=6379, db=1, password='')
        redis.srem('斗图网','None')
        for i in redis.smembers('斗图网'):
            t=str(i,encoding='utf8')
                #print(t)
            r=t.split('/')[-1]
            opp='/'+r

                    #dizhi='F:/斗图/'+r
            req=requests.get(t)
            if not os.path.exists(cu):
                os.mkdir(cu)


            with open(cu+opp,'wb')as p:
                p.write(req.content)
                print('保存完毕 已保存了%d张'%o)
                o+=1
    except e.MissingSchema as p:
        print('出现异常:',p.args)
        pass

test()
